# -*-coding:utf-8 -*- #
# ---------------------------------------------------------------------------
# ProjectName:   ApiTest
# FileName:      read_json.py
# Author:       liu
# Datetime:     2024/9/7 上午11:37
# Description: 读取json数据
# ---------------------------------------------------------------------------
import json

from ApiTest.common.read_user_ini import Read_user_ini
from ApiTest.report import log


def read_json(username, json_name):
    # 获取json文件
    read_ini = Read_user_ini(username=username)
    json_path = read_ini.get_file(json_name)
    # print(json_path)
    # 获取json文件对象
    try:
        with open(json_path, mode='r', encoding='utf-8') as f:
            log.info(f'加载json文件{json_path}成功!')
            return json.load(f)
    except Exception as e:
        log.error(f'请检查{json_path}')
        raise e


if __name__ == '__main__':
    print(read_json(username='test_demo', json_name='case'))